import { axios } from './request'

// 获取对应iid的商品数据
export function getdetail(iid) {
  return axios({
    url: '/detail',
    params: {
      iid
    }
  })
}

// 获取推荐数据
export function getRecommend() {
  return axios({
    url: '/recommend'
  })
}

// 这里我们重构能够获取到的数据，之后再进行传输，这样能够拥有更好的可阅读性
export class Goods {
  constructor(itemInfo, columns, services) {
    // 商品名称
    this.title = itemInfo.title
    // 商品描述
    this.desc = itemInfo.desc
    // 商品最新价格
    this.newPrice = itemInfo.price
    // 原价
    this.oldPrice = itemInfo.oldPrice
    // 折扣力度
    this.discount = itemInfo.discountDesc
    // 销量数据
    this.columns = columns
    // shopinfo.services里的服务项目
    this.services = services
    // 当前价格
    this.nowPrice = itemInfo.highNowPrice
  }
}
// 重构店铺信息
export class Shop {
  constructor(shopInfo) {
    this.logo = shopInfo.shopLogo
    this.name = shopInfo.name
    this.fans = shopInfo.cFans
    this.sells = shopInfo.cSells
    this.score = shopInfo.score
    this.goodsCount = shopInfo.cGoods
  }
}

// 重构参数信息
export class GoodsParam {
  constructor(info, rule) {
    // 注: images可能没有值(某些商品有值, 某些没有值)
    this.image = info.images ? info.images[0] : ''
    this.infos = info.set
    this.sizes = rule.tables
  }
}